#include <easylog.h>

void log(const std::string& name)
{
    easylog::logger::ptr lgr = easylog::registry::instance().get(name);

    lgr->set_flush_every(easylog::time_enum::t1min);

    int i = 0;
    while (true)
    {
        lgr->info("rolling sink now, {}", i++);
        std::this_thread::sleep_for(std::chrono::milliseconds(100));
    }
}

int main(int argc, char* argv[])
{
    if (argc != 3)
    {
        std::cout << "Usage:\n\t " << argv[0] << " max_live_time " << " back_dir_path \n\t such as: " << argv[0] << " 3 back_dir" << std::endl;
        exit(1);
    }

    int max_live_time = std::stoi(argv[1]);
    std::string back_dir_path = argv[2];

   easylog::logger_builder::ptr glb = std::make_shared<easylog::global_logger_builder>();
   glb->build_logger_type(easylog::logger_type::async);
   glb->build_logger_name("rolling");
   glb->build_sinker<easylog::roll_over_time>(back_dir_path + "/time_rolling_log-%d{%Y%m%d-%H%M%S}.log", 
                                              100, 
                                              max_live_time, // easylog::time_enum::t20sec,
                          easylog::size_enum::m1GB);

   glb->build_work_type(easylog::worker_type::unsafe);
   glb->build_thread_num(2);
   glb->build_buffer_size(easylog::size_enum::m10KB);
   glb->build_buffer_increment(easylog::size_enum::m5KB);
   glb->build_buffer_threshold(easylog::size_enum::m50KB);

   glb->build();

   log("rolling");
   
   return 0;
}
